from pydantic import BaseModel, EmailStr
from typing import Optional, List
from datetime import datetime


class AuthorBase(BaseModel):
    username: str


# 请求体校验模型
class AuthorCreate(AuthorBase):
    email: EmailStr


# 响应体校验模型
class Author(AuthorBase):
    id: int
    email: EmailStr

    class Config:
        orm_mode = True


class PublishBase(BaseModel):
    name: str


# 出版社请求校验模型
class PublishCreate(PublishBase):
    pass


# 出版社响应体模型
class Publish(PublishBase):
    id: int

    class Config:
        orm_mode = True


class BookBase(BaseModel):
    title: str
    price: float
    publish_date: Optional[datetime]


# 创建书籍请求体校验模型
class BookCreate(BookBase):
    pass


# 创建书籍响应体校验模型
class Book(BookBase):
    auth_id: int

    class Config:
        orm_mode = True
